package com.easysale.controllers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easysale.domain.Category;
import com.easysale.domain.Product;
import com.easysale.modelview.ProductResponse;
import com.easysale.modelview.ProductsResponse;
import com.easysale.services.ProductService;

@Controller
public class ProductController extends EasySaleController {

	@Autowired
	ProductService productService;
	
    @RequestMapping(value="/products/{productId}", method= RequestMethod.GET, produces="application/json")
    @ResponseBody
    public ProductResponse getProduct(@PathVariable int productId) throws IOException {
        System.out.println("Product retrieved.");
        return new ProductResponse(true,(Product)productService.products().get(productId));
    }
    
    @RequestMapping(value = "/products", method = RequestMethod.GET, produces="application/json")
    @ResponseBody
    public ProductsResponse getProducts() {
    	List<Product> products = productService.products();
        return new ProductsResponse(true,products);
    }    
}
